import request from "./request/index.js";

export async function addProduct(data) {
    try {
        const res = await request.post("/product", data);
        return res.data;
    } catch (err) {
        return Promise.reject(err);
    }
}

export async function listProducts(data) {
    try {
        const res = await request.post("/product/list", data);
        return res.data;
    } catch (err) {
        return Promise.reject(err);
    }
}

export async function getProduct(id) {
    try {
        const res = await request.get(`/product/${id}`);
        return res.data;
    } catch (err) {
        return Promise.reject(err);
    }
}

export async function updateProduct(data) {
    try {
        const res = await request.put("/product", data);
        return res.data;
    } catch (err) {
        return Promise.reject(err);
    }
}

export async function deleteProduct(id) {
    try {
        const res = await request.delete(`/product/${id}`);
        return res.data;
    } catch (err) {
        return Promise.reject(err);
    }
}
